import numpy as np


def jackknife_mean_optimized(x):
    n = len(x)
    x_sum = np.sum(x)
    x_mean = x_sum / n

    results = np.zeros(n)
    for i in range(n):
        # 计算去掉第i个元素后的均值
        mean_excluding_i = (x_sum - x[i]) / (n - 1)
        results[i] = mean_excluding_i

    jackknife_mean = np.mean(results)
    jackknife_variance = ((n - 1) / n) * np.sum((results - jackknife_mean) ** 2)

    return jackknife_variance


# 计算给定x取值的函数返回值
x_values = [99, 81, 76, 68, 18, 55, 32, 45]
print(jackknife_mean_optimized(x_values))
